﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DingApi.Models;
using System.Data;

using System.Web;
using Dingding.Helper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/*
 * 材料处置
 * 
 */
namespace DingApi.Controllers
{
    [RoutePrefix("api/Ym91inq")]
    public class Ym91inqController : ApiController
    {

         
        

        /// <summary>
        /// 退库材料号扫描
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("PostYm91inq_mat_no_inq")]
        public System.Data.DataSet PostYm91inq_mat_no_inq([FromBody]  JObject obj)
        {
            //系统信息；
            EI.EIInfo outBlock = new EI.EIInfo();
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            

            string MAT_NO   = obj["MAT_NO"] == null ? "" : obj["MAT_NO"].ToString().Trim();
           

            string sql_temp = ""; 
            EI.EIInfo Block_TPMMM02N = new EI.EIInfo(); 
            EI.EIInfo Block_TMM0001 = new EI.EIInfo();


            if (MAT_NO == "")
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "请先扫描材料号！");
                return outBlock;
            }


            string sql_str0 = " select LOCATION_NO,MAT_NO, mat_wt,PROD_CODE,PROD_LOT_NO,qual_grade_code,Pack_Mode_Name ";
            sql_str0 += "       ,pack_mode_code,stock_no,mat_spec_desc";
            sql_str0 += "       ,SG_STD,SG_SIGN    ";
            sql_str0 += "       ,decode(trim(OUT_TIME), '', REC_CREATE_TIME, OUT_TIME)  OUT_TIME,DUTY_MAKER  ";
            sql_str0 += "      ,STATUS,DPTMENT_CODE ,' ' QUAL_GRADE_NAME  from TPMMM02N                                                                                  ";
            sql_str0 += "       where mat_no = '" + MAT_NO + "' ";

            sql_str0 = sql_str0 + " union " + sql_str0.Replace("TPMMM02N", "HPMMM02N");

            



               Block_TPMMM02N = EF.Utility.ExecQuery(sql_str0);
            if (Block_TPMMM02N.Tables[0].Rows.Count < 1)
            {

                outBlock.Tables["SYS"].Rows.Add(-1, "标签材料[" + MAT_NO + "]不存在！");
                return outBlock;
            }

            Block_TPMMM02N.Tables[0].TableName = "T1";
            outBlock.Tables.Add(Block_TPMMM02N.Tables[0].Copy());
 


            string sql_str = " select  ";
            sql_str += " to_char(to_date(rec_create_time,'yyyymmddhh24miss'),'yyyy-mm-dd hh24:mi') REC_CREATE_TIME ";
            sql_str += " ,REC_CREATOR,REMARK1 ";
            sql_str += " from tpmmm02n9 t where  ROW_GUID='" + MAT_NO + "'";
            sql_str += " order by t.REC_CREATE_TIME desc  ";
            Block_TMM0001 = EF.Utility.ExecQuery(sql_str);

            

            
            


            Block_TMM0001.Tables[0].TableName = "T29";
            outBlock.Tables.Add(Block_TMM0001.Tables[0].Copy());
            


            outBlock.Tables["SYS"].Rows.Add(0, "");
            return outBlock;

        }



          

 



        
 

    }
}